<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
      * {
        padding: 0;
        margin: 0;
        list-style: none;
      }
      .look {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        background: rgba(0, 0, 0, 0.4);
      }
      .con {
        width: 300px;
        height: 300px;
        position: absolute;
        top: 100px;
        left: 100px;
        background-color: #fff;
      }
    </style>
  </head>
  <body>
    <!-- fu -->
    <div id="box">
      <h3 v-show="filterList.length > 0">
        爱好：
        <span v-for="(item, index) in filterList"> --{{item.title}} </span>
      </h3>
      <button @click="bounce">弹框</button>
      <ne v-show="flag" @send="fff"></ne>
    </div>
    <!-- zi -->
    <template id="pop">
      <div class="look">
        <div class="con">
          <ul>
            <li v-for="(item, index) in list">
              <input v-model="item.check" type="checkbox" /> {{item.title}}
            </li>
          </ul>
          <button @click="close">取消</button>
          <button @click="confirm">确定</button>
        </div>
      </div>
    </template>
    <script>
      Vue.config.productionTip = false;
      //子
      const pop = {
        template: "#pop",
        data() {
          return {
            list: [
              {
                title: "篮球",
                check: false,
              },
              {
                title: "足球",
                check: false,
              },
              {
                title: "拍球",
                check: false,
              },
              {
                title: "地球",
                check: false,
              },
            ],
          };
        },
        methods: {
          //取消
          close() {
            this.$emit("send", {
              flag: false,
            });
          },
          //确定
          confirm() {
            this.$emit("send", {
              flag: false,
              list: JSON.parse(JSON.stringify(this.list)),
            });
          },
        },
      };
      //父
      new Vue({
        el: "#box",
        computed: {
          filterList() {
            return this.list.filter((item) => item.check);
          },
        },
        components: {
          ne: pop,
        },
        data() {
          return {
            flag: false,
            list: [],
          };
        },
        methods: {
          bounce() {
            this.flag = true;
          },

          fff({ flag, list }) {
            this.flag = flag;
            //点击了确定
            if (list) {
              this.list = list;
            }
          },
        },
      });
    </script>
  </body>
</html>
